Skip to content

Update mgca to use type const syntax instead of the #[type_const] attribute. #152324

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Keith-Cancel:mgca4
Feb 10, 2026
Merged

Update mgca to use type const syntax instead of the #[type_const] attribute. #152324
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Keith-Cancel:mgca4

Conversation

@Keith-Cancel
Copy link
Contributor

@Keith-Cancel Keith-Cancel commented Feb 8, 2026

This PR changes the #[type_const] attribute to the type const syntax for #132980.

This will fixes #151273 and similar issues, since we need to check type const of items before expansion. The move to add a syntax was mentioned here: #151289 (comment)

The first part of this PR adds support by allowing type const <IDENT>: <TYPE> { = <EXPR> }; syntax in rustc_parse/src/parser/item.rs.

The next part since the AST item does not contain enough information to determine if we have a type const was rework ConstItemRhs into ConstItemRhsKind to store the information since we no longer have the attribute acting as a source of extra data/metadata.

The hir node ConstItemRhsKind current shape mostly works, except in the case of TraitItemKind where it is an option. I initially went about giving hir::ConstItemRhsKind a similar form the AST, but it touches a lot more lines of code and files so because of that, the less invasive option was to add a simple boolean flag to TraitItemKind.

The forth part of this PR includes adding a query I called is_rhs_type_const so that we can handle both local and foreign def_ids.

The fifth aspect of the PR is adding a mgca_type_const_syntax feature gate that is checked before expansion. The standard mgca feature gate is ran after expansion. This feature gate allows for conditional compilation (e.g #[cfg(..)]) of the type const syntax in nightly without min_generic_const_args being enabled.

The last bit is updating all the the tests that used the #[type_const] attribute to use the new syntax that failed because of the changes. This is the bulk of touched/edited files in the PR.

r? @BoxyUwU
@rustbot label +F-associated_const_equality +F-min_generic_const_args

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred in tests/ui/sanitizer

cc @rcvalle

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. F-associated_const_equality `#![feature(associated_const_equality)]` F-min_generic_const_args `#![feature(min_generic_const_args)]` labels Feb 8, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind going through and fully removing the type_const attribute? It looks like it shouldn't be too involved. It's mostly just in comments which can be trivially changed to say type const instead of #[type_const] or would just need minor re-flowing. You should be able to find the dozen or so locations by searching for type_const] in the compiler.

Removing the actual parsing/whatnot of #[type_const] should be fairly simple too I think. It's:

  • delete TypeConstParser
  • remove type_const from rustc_span/src/symbol.rs
  • remove it from the list of builtin attrs, rustc_feature/src/builtin_attrs.rs

I realise this PR is already fairly big but I don't think this should make it that much larger, but will pretty much "finish" everything off for this change and that feels quite valuable to me.

View changes since this review

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2026

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

HIR ty lowering was modified

cc @fmease

Some changes occurred to constck

cc @fee1-dead

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 9, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-bors

This comment has been minimized.

@Keith-Cancel Keith-Cancel marked this pull request as draft February 9, 2026 11:45
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 9, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 9, 2026

idk if that's spurious or not so lets just do CI again...

@BoxyUwU BoxyUwU closed this Feb 9, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 9, 2026
@BoxyUwU BoxyUwU reopened this Feb 9, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 9, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 9, 2026

@bors r+ rollup=never p=1 (probably bitrots given its size)

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 9, 2026

📌 Commit 73a991f has been approved by BoxyUwU

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 9, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 10, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 10, 2026

☀️ Test successful - CI
Approved by: BoxyUwU
Duration: 3h 46m 55s
Pushing 381e9ef to main...

@rust-bors rust-bors bot merged commit 381e9ef into rust-lang:main Feb 10, 2026
18 of 26 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 10, 2026
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 18d13b5 (parent) -> 381e9ef (this PR)

Test differences

Show 29 test diffs

Stage 1

  • [ui] tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs: [missing] -> pass (J0)

Additionally, 27 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 381e9ef09effbed5f1378a24dc6e461fea35a0e1 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-apple: 1h 51m -> 2h 47m (+50.2%)
  2. pr-check-1: 24m 27s -> 31m 23s (+28.4%)
  3. x86_64-gnu-miri: 1h 9m -> 1h 23m (+20.3%)
  4. aarch64-apple: 3h 7m -> 3h 40m (+17.8%)
  5. x86_64-gnu-tools: 54m 14s -> 1h 3m (+17.4%)
  6. pr-check-2: 38m 9s -> 44m 13s (+15.9%)
  7. x86_64-rust-for-linux: 45m 16s -> 51m 52s (+14.6%)
  8. x86_64-mingw-1: 2h 35m -> 2h 57m (+14.3%)
  9. i686-gnu-2: 1h 29m -> 1h 41m (+13.8%)
  10. aarch64-gnu-debug: 1h 8m -> 1h 17m (+13.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (381e9ef): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.1%, 0.7%] 18
Regressions ❌
(secondary)
0.5% [0.0%, 1.7%] 13
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 4
All ❌✅ (primary) 0.4% [0.1%, 0.7%] 18

Max RSS (memory usage)

Results (primary 2.3%, secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.0%, 2.4%] 3
Regressions ❌
(secondary)
3.7% [2.2%, 5.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-5.1%, -2.4%] 2
All ❌✅ (primary) 2.3% [2.0%, 2.4%] 3

Cycles

Results (primary 1.9%, secondary -4.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.9% [1.9%, 1.9%] 1
Regressions ❌
(secondary)
2.8% [2.8%, 2.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.4% [-7.0%, -4.2%] 5
All ❌✅ (primary) 1.9% [1.9%, 1.9%] 1

Binary size

Results (primary 0.6%, secondary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.6% [0.0%, 1.2%] 78
Regressions ❌
(secondary)
0.5% [0.0%, 1.6%] 32
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [0.0%, 1.2%] 78

Bootstrap: 474.211s -> 509.869s (7.52%)
Artifact size: 397.99 MiB -> 398.00 MiB (0.00%)

@Kobzol
Copy link
Member

Kobzol commented Feb 17, 2026

Small regressions on libc and bitmaps, @BoxyUwU do you think there might be something to improve here, or let's accept it due to the size of the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) F-associated_const_equality `#![feature(associated_const_equality)]` F-min_generic_const_args `#![feature(min_generic_const_args)]` merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: thir_body queried for type_const (via cfg_attr)

6 participants